package net.amsoft.iservice.isso.hibernate.tests;
import net.amsoft.iservice.isso.hibernate.IBroker;
import net.amsoft.iservice.isso.util.ISSOHelpers;
import net.amsoft.iservice.util.HibernateUtil;
import net.amsoft.iservice.util.exception.IServiceException;

public class IBrokerTest
{
    private static int loopBroker = 0;

    public static void mB() throws IServiceException {
        IBroker oIBroker = new IBroker();
        loopBroker = 0;
        oIBroker.setServerName("isso.ibroker" + loopBroker + ".amsoft.co.in");
        oIBroker.setDescription("broker " + loopBroker);
        System.out.println("-----------IBROKER CREATE");
        oIBroker.setState((short) 1);
        oIBroker.insert();
        loopBroker++;
        // HibernateUtil.getSessionFactory().close();
    }
    private static void uB() throws IServiceException {
        IBroker oIBroker = ISSOHelpers.fetchIBroker("isso.ibroker" + loopBroker
                + ".amsoft.co.in");
        oIBroker.setState((short) 1);
        oIBroker.update();
        loopBroker++;
    }
    private static void rB() throws IServiceException {
        IBroker oIBroker = ISSOHelpers.fetchIBroker("isso.ibroker" + loopBroker
                + ".amsoft.co.in");
        oIBroker.remove();
        loopBroker++;
    }

    private static void fB() throws IServiceException {
        System.out.println(loopBroker);
        IBroker oIBroker = ISSOHelpers.fetchIBroker("isso.ibroker" + loopBroker
                + ".amsoft.co.in");
        System.out.println(oIBroker.getState() + ">>>>>>>>"
                + oIBroker.getServerName());
        //oIBroker.update ();
        loopBroker++;
    }

    public static void main(String[] args) throws IServiceException {
        System.out.println("--------------CREATE------------------");
        loopBroker = 0;
        mB();
        mB();
        mB();
        mB();
        mB();
        mB();
        IBroker.listAll();

        //        System.out.println("--------------FETCH------------------");
        //        loopBroker = 0; fB (); fB (); fB (); fB (); fB (); fB
        // ();IBroker.listAll();
        //        
        //      System.out.println("--------------UPDATE------------------");
        //      loopBroker = 0; uB (); uB (); uB (); uB (); uB (); uB ();
        // IBroker.listAll ();
        //        
        //        
        //        System.out.println("--------------REMOVE------------------");
        //        loopBroker = 0; rB (); rB (); rB (); rB (); rB (); rB ();
        // IBroker.listAll ();

        HibernateUtil.getSessionFactory().close();
    }
}